Description
CDL's counting semaphores (CSMs) can be used as a direct equivalent to conventional counting semaphores. If a request is issued to a semaphore that has a non-zero value then the request will proceed and the semaphore's value will be decremented. If a request is issued to a semaphore with a zero value, then the requester will be added to a queue of blocked requesters and the semaphore's value left at zero. Each time the semaphore is signaled, its value is incremented. If there are any blocked requesters, then the first requester in the queue is unblocked, and the count decremented back to zero.
Creation Attributes
Name
Instance name (see Object Names)
Dimensions
Instance dimensionality (see Object Dimensionality)
Presence
Instance presence flag (see Object Presence)
Initial Value
This attribute determines the initial value that the semaphore is created with.
Connection Attributes
Counting semaphore connections require the following attributes;
Timeout
This attribute determines whether the connection will poll or block (see Connection Timeout).
Signature
This attribute is a string that describes the mapping from elements in the consumer, to elements in the counting semaphore. See Connection Mappings.
Dimensions
This attribute determines the dimensionality of the connection array owned by each consuming element. By default, this will provide the consuming element with one connection for each provider element. Collector, Multiplexor and Manual connection consumers can have multi-dimensional connection arrays, but in all other cases, this attribute will be '1'. See Connection Mappings.
Repeat Count
This attribute determines the number of times that each 'provider element to consumer element' connection is repeated. If the repeat count is greater then one, then the Dimensions attribute (above), and the resulting connection access functions, will both have an 'extra' dimension. Only Collector, Multiplexor and Manual connection consumers can have repeat counts that are greater than '1'. See Connection Mappings.
Name
This attribute determines the connection's 'name' which is used to construct access function names (see Connection Names).
Access
This attribute determines whether the consumer is requesting or signaling.
Additional attributes may also be required that are specific to the connection's consuming object. These are documented in their respective sections.
Manual Connections
Manual connections provide a means of directly accessing target objects. These are created automatically from CDL diagrams and accessed using their access function names (see Manual Connections).
Counting semaphore connections provide the following member functions;
Request()
This member function issues a request to the counting semaphore (see CSM request function).
Signal()
This member function signals the counting semaphore(see CSM signal function).
Automatic and Manual Connections
The following member functions can be used to retrieve information from both automatic and manual connections;
IsOpen()
This member function returns TRUE if the request has succeeded or FALSE otherwise.
Notes
There are several points to bear in mind when using counting semaphores;
When automatic connections are made to counting semaphores they can be connected for 'request' or 'signal' access. If they are connected for 'request' access then the consumer will block until the semaphore generates an event. If they are connected for 'signal' access however then the consumer will not block when opening but instead will signal the semaphore when closing. This means that consumers could race (nothing to block them) and so typically automatic connection signal access only occurs as part of a 'collection' operation. This also means that counting semaphores can be used to implement a mutex mechanism (see example below).
Examples
See Exclusion and Atomic Operations.